﻿using System;
using UnityEngine;

namespace UnityStandardAssets.ImageEffects
{
	// Token: 0x020005CE RID: 1486
	[AddComponentMenu("Image Effects/Blur/Blur")]
	[ExecuteInEditMode]
	public class Blur : MonoBehaviour
	{
		// Token: 0x1700022B RID: 555
		// (get) Token: 0x06001D54 RID: 7508 RVA: 0x0001270D File Offset: 0x0001090D
		public Material material
		{
			get
			{
				if (Blur.m_Material == null)
				{
					Blur.m_Material = new Material(this.blurShader);
					Blur.m_Material.hideFlags = HideFlags.DontSave;
				}
				return Blur.m_Material;
			}
		}

		// Token: 0x06001D55 RID: 7509 RVA: 0x00012740 File Offset: 0x00010940
		public void OnDisable()
		{
			if (Blur.m_Material)
			{
				UnityEngine.Object.DestroyImmediate(Blur.m_Material);
			}
		}

		// Token: 0x06001D56 RID: 7510 RVA: 0x00067014 File Offset: 0x00065214
		public void Start()
		{
			if (!SystemInfo.supportsImageEffects)
			{
				base.enabled = false;
				return;
			}
			if (!this.blurShader || !this.material.shader.isSupported)
			{
				base.enabled = false;
				return;
			}
		}

		// Token: 0x06001D57 RID: 7511 RVA: 0x00067060 File Offset: 0x00065260
		public void FourTapCone(RenderTexture source, RenderTexture dest, int iteration)
		{
			float num = 0.5f + (float)iteration * this.blurSpread;
			Graphics.BlitMultiTap(source, dest, this.material, new Vector2[]
			{
				new Vector2(-num, -num),
				new Vector2(-num, num),
				new Vector2(num, num),
				new Vector2(num, -num)
			});
		}

		// Token: 0x06001D58 RID: 7512 RVA: 0x000670E0 File Offset: 0x000652E0
		public void DownSample4x(RenderTexture source, RenderTexture dest)
		{
			float num = 1f;
			Graphics.BlitMultiTap(source, dest, this.material, new Vector2[]
			{
				new Vector2(-num, -num),
				new Vector2(-num, num),
				new Vector2(num, num),
				new Vector2(num, -num)
			});
		}

		// Token: 0x06001D59 RID: 7513 RVA: 0x00067158 File Offset: 0x00065358
		public void OnRenderImage(RenderTexture source, RenderTexture destination)
		{
			int width = source.width / 4;
			int height = source.height / 4;
			RenderTexture renderTexture = RenderTexture.GetTemporary(width, height, 0);
			this.DownSample4x(source, renderTexture);
			for (int i = 0; i < this.iterations; i++)
			{
				RenderTexture temporary = RenderTexture.GetTemporary(width, height, 0);
				this.FourTapCone(renderTexture, temporary, i);
				RenderTexture.ReleaseTemporary(renderTexture);
				renderTexture = temporary;
			}
			Graphics.Blit(renderTexture, destination);
			RenderTexture.ReleaseTemporary(renderTexture);
		}

		// Token: 0x040016AE RID: 5806
		[Range(0f, 10f)]
		public int iterations = 3;

		// Token: 0x040016AF RID: 5807
		[Range(0f, 1f)]
		public float blurSpread = 0.6f;

		// Token: 0x040016B0 RID: 5808
		public Shader blurShader;

		// Token: 0x040016B1 RID: 5809
		public static Material m_Material;
	}
}
